<template>
  <div class="mt20 wrap" v-loading="loading">
    <div v-for="item in formSection" :key="item.code">
      <anchor :title="item.title"></anchor>
      <div v-if="item.typeCode == 'FORM'">
        <zcb-form
          :isPreview="true"
          :isPurchaser="false"
          :modelValue="item.key == '' ? detailsInfo : detailsInfo[item.key]"
          :schema="item.formTemplateFieldVOList"
          :options="formOptions"
          :currencyInfo="detailsInfo?.currency && !isEmptyObject(detailsInfo?.currency) ? detailsInfo?.currency : getTenantInfo()"
        >
          <!-- <template #relativeFirstExclTax>
            {{ detailsInfo?.currency }}
            {{ detailsInfo.relativeFirstExclTax || detailsInfo.relativeFirstExclTax === 0 ? detailsInfo.relativeFirstExclTax : '--' }}
        </template> -->
          <template #strategy>
            {{ detailsInfo.strategyCn }}
          </template>
          <template #code>
            <el-button type="info" link @click="goSourcingDetail(detailsInfo)">{{ detailsInfo.code }}</el-button>
          </template>
        </zcb-form>
      </div>
      <div v-else-if="item.typeCode == 'LIST'">
        <!-- 需求信息 -->
        <!-- <row-table-v4
          :mode="[1]"
          :columnL="(item.formTemplateFieldVOList || []).slice(0, 10)"
          :tableList="item.key == '' ? detailsInfo : detailsInfo[item.key]"
          v-if="item.code == 'sourcing_item_requirement_list'"
          :isPreview="true"
        >
        </row-table-v4> -->
        <!-- 供应商 -->
        <row-table-v1
          :isPreview="true"
          :showIndex="true"
          :column="item.formTemplateFieldVOList.slice(0, 10)"
          :tableData="item.key == '' ? detailsInfo : detailsInfo[item.key]"
          :showActionBtn="false"
          :currencyInfo="detailsInfo?.currency && !isEmptyObject(detailsInfo?.currency) ? detailsInfo?.currency : getTenantInfo()"
        >
          <template #firstAwardFlag="{ scope }">
            {{ scope.firstAwardFlag === true ? '是' : '否' }}
          </template>
          <!-- <template #sourceType="{ scope }">
            {{ scope.sourceType == 1 ? '库内导入' : scope.sourceType == 1 ? '手工录入' : scope.sourceType == 3 ? '平台供应商' : '' }}
          </template> -->
          <template #vendorMaterialCatalogId="{ scope }">
            {{ scope.vendorMaterialCatalogName }}
          </template>
        </row-table-v1>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { getTenantInfo } from 'utils/headerToken'
import { isEmptyObject } from 'utils/validate'
import { getTempInfoApi } from '@/api/common'
import { ERR_OK } from 'config/statusCode'
import listMixins from '@/hooks/useList'
import { useI18n } from 'vue-i18n'
const { t } = useI18n() // 中英文
const props = defineProps({
  componentObject: {
    // 返回的对象值
    type: Object,
    default() {
      return {}
    }
  }
})

// const tenantInfo = ref({})
// tenantInfo.value = getTenantInfo()
const loading = ref(false)
const formSection = ref([])
const detailsInfo = ref(JSON.parse(props.componentObject.detail))
let { formOptions } = listMixins()

//获取模版
const getTeml = async () => {
  loading.value = true
  let { templateVersion, templateCode } = props.componentObject
  const { code, data } = await getTempInfoApi(templateCode, templateVersion || '')
  if (code == ERR_OK) {
    formSection.value = data.formSectionVOList.filter(
      (item) => item.formTemplateFieldVOList && item.formTemplateFieldVOList.length > 0 && item.formTemplateFieldVOList != null
    )
    formSection.value.forEach((item) => {
      if (item.typeCode == 'FORM') {
        if (item.code == 'sourcing_item_basic') {
          // 事件信息
          item.key = ''
        } else if (item.code == 'sourcing_item_price_information') {
          // 价格信息
          item.key = ''
        } else if (item.code == 'sourcing_item_calibration_instructions') {
          // 定标说明
          item.key = ''
        }
      } else if (item.typeCode == 'LIST') {
        if (item.code == 'sourcing_item_supplier_list') {
          // 供应商名单
          item.key = 'participatingVendorVOList'
        } else if (item.code == 'sourcing_item_award_information') {
          // 授标信息
          item.key = 'awardVendorVOS'
        }
      }
    })
    loading.value = false
    console.log(formSection.value)
    console.log(detailsInfo.value)
  }
}

onMounted(() => {
  getTeml()
})

const goSourcingDetail = (item) => {
  history.pushState(null, null, `/sourcing/sourcingList/eventDetail?id=${item.id}&source=detail`)
}
</script>

<style lang="scss" scoped>
.wrap {
  width: 98%;
  padding-right: 2%;
}
.mt20 {
  margin-top: 20px;
}
.title {
  display: flex;
  flex: 1;
  justify-content: space-between;
  & > div {
    color: var(--el-color-primary);
  }
}
.block {
  margin-bottom: 32px;
}
:deep(.row-table-v4) {
  padding-bottom: 32px;
}
:deep(.row-table) {
  padding-bottom: 0;
  .btn-list {
    padding: 0;
  }
}
</style>
